#include "exercise_i2c_pcf8563.h"
#include <stdio.h>
#include "bmp.h"
#include "oled.h"
#include <stdlib.h>

void exercise_i2c_pcf8563_test(void)
{
    //systick_config();
    // i2c_soft_config();
    /// i2c_hard_config();
    PCF8563_init();
    // LED_Init();  // 初始化LED
    OLED_Init(); // 初始化OLED

    Clock_t clk;
    clk.year = 2055;
    clk.month = 4;
    clk.week = 7;
    clk.day = 27;
    clk.hour = 10;
    clk.minute = 53;
    clk.second = 52;

    //delay_1ms(3000);
    PCF8563_set_clock(clk);
    //
    char dateStr[20] = {0};

    while (1)
    {
        PCF8563_get_clock(&clk);

        printf("%d-%d-%d %d:%d:%d\n", clk.year, clk.month, clk.day, clk.hour, clk.minute, clk.second);
        memset(dateStr, 0, sizeof(dateStr));
        snprintf(dateStr, 20, "%4d-%02d-%02d %02d:%02d:%02d", clk.year, clk.month, clk.day, clk.hour, clk.minute, clk.second);

        //
         OLED_Clear();
        OLED_ShowString(0, 0, (uint8_t *)dateStr, 8, 1); // 6*8 “ABC”
        OLED_Refresh();

        delay_1ms(1000);
        // OLED_ScrollDisplay(11, 4, 1);
    }
}
